﻿using System;
using System.Linq;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.DataLayer.Infra;
using ProjetoComperio.Framework.Extensions;

namespace ProjetoComperio.BusinessLogicLayer
{
    public class AcademicPersonCVBLL : ComperioDataObject
    {
        /// <summary>
        /// This method inserts a new Academic Person CV
        /// </summary>
        /// <param name="academicPersonCV"></param>
        public void Create(AcademicPersonCV academicPersonCV)
        {
            DbContext.AcademicPersonCVs.Add(academicPersonCV);
            DbContext.SaveChanges();
        }
        
        /// <summary>
        /// This method edits a acdemic person CV
        /// </summary>
        /// <param name="academicPersonCV"></param>
        public void Edit(AcademicPersonCV academicPersonCV)
        {
            AcademicPersonCV original = this.CatchAcademicPersonCV(academicPersonCV.AcademicPersonID);
            original.CopyValuesFrom(academicPersonCV);
            DbContext.SaveChanges();
        }

        /// <summary>
        /// This method retrieve a specific Retrive Academic PersonCV
        /// </summary>
        /// <param name="academicPersonCVID"></param>
        /// <returns></returns>
        public IQueryable<AcademicPersonCV> RetriveAcademicPersonCV(int academicPersonID)
        {
            return DbContext.AcademicPersonCVs;
        }
        
        /// <summary>
        /// Catch the academic CV of the person concerned
        /// </summary>
        /// <param name="academicPersonCVID"></param>
        /// <returns></returns>
        public AcademicPersonCV CatchAcademicPersonCV(int academicPersonCVID)
        {
            return DbContext.AcademicPersonCVs.Where(p => p.AcademicPersonCVID == academicPersonCVID).FirstOrDefault();
        }

        public AcademicPersonCV RetrieveAcademicPersonCVByAcademicPersonID(int academicPersonID)
        {
            return DbContext.AcademicPersonCVs.Where(p => p.AcademicPersonID == academicPersonID).FirstOrDefault();
        }
        
        /// <summary>
        /// This method returns all the Academic Person CV inside from db
        /// </summary>
        /// <returns></returns>
        public IQueryable<AcademicPersonCV> AcademicPersonCVs()
        {
            return DbContext.AcademicPersonCVs;
        }

        /// <summary>
        /// This method removes a specific Academic Person CV from db
        /// </summary>
        /// <param name="academicPersonID"></param>
        public void Remove(int academicPersonID)
        {
            //DbContext.AcademicPersonCVs.Remove(this.RetriveAcademicPersonCV(academicPersonID));
            //DbContext.SaveChanges();
        }
    }
}
